package com.HsqlDBTest;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class DBConnection{
	private Connection conn = null;
				
	public Connection getConnection(){
		try{
			Class.forName("org.hsqldb.jdbcDriver");
			conn = DriverManager.getConnection("jdbc:hsqldb:MyDB2","sa","");
		}catch(SQLException sqle){
			sqle.printStackTrace(System.out);
		}catch(ClassNotFoundException cnfe){
			cnfe.printStackTrace(System.out);
		}
		
		return conn;
	}
	
	public void destroyConnection(ResultSet rs, PreparedStatement pstmt, Connection con){
		try{
			if(rs != null){
				rs.close();
			}
			
			if(pstmt != null){
				pstmt.close();
			}
			
			if(con != null){
				con.close();
			}
			
		}catch(Exception e){
			e.printStackTrace(System.out);
		}
	}
}
